package org.me.nyx.data;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Observable;

public class DataAdapter<T extends Observable> extends ArrayAdapter<T> {
    private Activity activity;
    protected ArrayList<T> list = new ArrayList<T>();
    protected LayoutInflater layoutInflater;

    public DataAdapter(Activity activity, int textViewResourceId) {
		super(activity, textViewResourceId);

		this.activity = activity;
		layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public synchronized void setData(final ArrayList<T> list) {
		final DataAdapter<T> me = this;
		
		activity.runOnUiThread(new Runnable() {
			public void run() {
			me.list = list;
			setNotifyOnChange(false);

			clear();
			for(T item : list)
				add(item);

			notifyDataSetChanged();
			}
		});
    }

    public synchronized void dispose() {

    }
}
